﻿//----------------------------------------------
// Flip Web Apps: Game Framework
// Copyright © 2016 Flip Web Apps / Mark Hewitt
//
// Please direct any bugs/comments/suggestions to http://www.flipwebapps.com
// 
// The copyright owner grants to the end user a non-exclusive, worldwide, and perpetual license to this Asset
// to integrate only as incorporated and embedded components of electronic games and interactive media and 
// distribute such electronic game and interactive media. End user may modify Assets. End user may otherwise 
// not reproduce, distribute, sublicense, rent, lease or lend the Assets. It is emphasized that the end 
// user shall not be entitled to distribute or transfer in any way (including, without, limitation by way of 
// sublicense) the Assets in any other way than as integrated components of electronic games and interactive media. 

// The above copyright notice and this permission notice must not be removed from any files.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//----------------------------------------------

using UnityEngine;
using UnityEngine.Assertions;

namespace GameFramework.UI.Dialogs.Components
{
    /// <summary>
    /// Shows the given dialog a single time
    /// </summary>
    /// A record is made of whether the specified dialog has been shown so that it is only shown one time including across game restarts.
    /// Use this component for showing things like help tips, guidelines or other one time information.
    [AddComponentMenu("Game Framework/UI/Dialogs/ShowDialogOnce")]
    [HelpURL("http://www.flipwebapps.com/unity-assets/game-framework/ui/dialogs/")]
    public class ShowDialogOnce : MonoBehaviour
    {
        /// <summary>
        /// A unique key that identifies this dialog used for checking if it has been previously displayed.
        /// </summary>
        [Tooltip("A unique key that identifies this dialog used for checking if it has been previously displayed.")]
        public string DialogKey;

        /// <summary>
        /// The name of a prefab to display. If not specified then the GeneralMessage prefab will be used.
        /// </summary>
        [Tooltip("The name of a prefab to display. If not specified then the GeneralMessage prefab will be used.")]
        public string PrefabName;

        /// <summary>
        /// An optional localisation key for the dialog title
        /// </summary>
        [Tooltip("Localisation key for the dialog title")]
        public string TitleKey;

        /// <summary>
        /// An optional localisation key for the dialog text
        /// </summary>
        [Tooltip("Localisation key for the dialog text")]
        public string TextKey;

        /// <summary>
        /// An optional localisation key for the dialog text 2
        /// </summary>
        [Tooltip("Localisation key for the dialog text 2")]
        public string Text2Key;

        /// <summary>
        /// An optional sprite to display
        /// </summary>
        [Tooltip("An optional sprite to display")]
        public Sprite Sprite;

        void Start()
        {
            Assert.IsTrue(DialogManager.IsActive, "To use the ShowDialogOnce component, you must have a DialogManager added to your scene.");
            Assert.IsFalse(string.IsNullOrEmpty(DialogKey), "You must specify the Dialogkey");

            DialogManager.Instance.ShowOnce(DialogKey, PrefabName, titleKey: TitleKey, textKey: TextKey, text2Key: Text2Key,
                sprite: Sprite);
        }
    }
}